// base
import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
// redux
import { connect } from '@tarojs/redux'
import { DOREQUESTJOBLIST } from './store/actions/pagejoblist'
import { UPDATEPAGEJOBLIST } from './store/types/pagejoblist'
// less
import './index.less'
// components
import CompanyBar from './components/company-bar'
import JobWrap from './components/job-wrap'

const mapActiontoProps = dispatch => ({
  updateState(payload) {
    dispatch({
      type: UPDATEPAGEJOBLIST,
      payload: {
        ...payload
      }
    })
  },
  dorequest() {
    dispatch(DOREQUESTJOBLIST())
  }
})

@connect(
  ({ pagejoblist }) => ({
    ...pagejoblist
  }),
  mapActiontoProps
)
class JobList extends Component {
  config = {
    enablePullDownRefresh: true
  }

  componentWillMount() {
    // onLoad
  }

  componentDidMount() {
    // onready
    this.delay(500).then(() => {
      this.props.updateState({
        animate: true
      })
    })
  }

  componentDidShow() {
    // onshow
  }

  componentDidHide() {
    // onhide
  }

  componentWillUnmount() {
    // onUnload
    this.delay(1000).then(() => {
      this.props.updateState({
        animate: false
      })
    })
  }

  onPullDownRefresh() {}

  onReachBottom() {}

  onPageScroll() {}

  delay(time = 0) {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve()
      }, time)
    })
  }

  render() {
    return (
      <View className="JobList_id20000">
        <CompanyBar detail={this.props.detail} />
        <JobWrap
          animate={this.props.animate}
          number={this.props.jobnumber}
          dataSource={this.props.joblist}
        />
      </View>
    )
  }
}

export default JobList
